package net.organizer.dao;

import javax.persistence.Id;
import org.json.JSONException;
import org.json.JSONObject;
import com.googlecode.objectify.Key;


public class Domain {
	protected String desc;
	@Id protected String name;
	protected Long version = 1L;
	
	public Key<Domain> getKey(){
		return new Key<Domain>(Domain.class, this.getName());
	}

	public static Key<Domain> getKey(String name){
		return new Key<Domain>(Domain.class, name);
	}

	public Domain() {
		super();
	}


	public Domain(String name, String desc) {
		super();
		this.name = name;
		this.desc = desc;
	}


	public String getDesc() {
		return desc;
	}

	public String getName() {
		return name;
	}

	public void setDesc(String desc) {
		this.desc = desc;
	}

	public void setName(String name) {
		this.name = name;
	}


	public void setVersion(Long version) {
		this.version = version;
	}


	public Long getVersion() {
		return version;
	}


	public JSONObject toJSONObject() {
		  JSONObject result = new JSONObject();
		  try {
			result.put("name", this.getName());
			result.put("desc", this.getDesc());
			result.put("version", this.getVersion());
		} catch (JSONException e) {
			throw new RuntimeException(e);
		}
		return result;
	}


	@Override
	public String toString() {
		return "Domain [ name=" + name + ", desc=" + desc + ", version=" + version + "]";
	}
}
